package com.lge.pitchingcoins.ui.clients;

import android.app.Activity;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.lge.pitchingcoins.R;
import com.lge.pitchingcoins.util.Util;

@Deprecated
public class ClientsMainActivity extends Activity implements OnClickListener {
    private EditText nickNameEditText = null;
    private Button gameConnectButton = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_clients_main);

        initComponent();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.gameConnectButton:
            gameConnectButtonPressed();
            break;
        }
    }    


    // Member Methods
    public void initComponent() {
        nickNameEditText = (EditText)findViewById(R.id.nickNameEditText);
        gameConnectButton = (Button)findViewById(R.id.gameConnectButton);

        nickNameEditText.setText(Util.getDeviceName(getContentResolver()));
        gameConnectButton.setOnClickListener(this);
    }

    public void gameConnectButtonPressed() {
        ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo networkInfoForWifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        
        if (networkInfoForWifi.isConnected()) {
            if (nickNameEditText.getText().toString().trim().length() > 0) {
                Intent intent = new Intent(ClientsMainActivity.this, GameConnectForClientsActivity.class);
                intent.putExtra("nickname", nickNameEditText.getText().toString());
                startActivity(intent);
            } else {
                Toast.makeText(getApplicationContext(), getString(R.string.inputNicknameText), Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(getApplicationContext(), getString(R.string.requireWifiConnectionText), Toast.LENGTH_SHORT).show();
        }
    }
}